package com.yeepay.skb.biz;

import com.yeepay.skb.util.Conts;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 结算接口
 */
public class WithdrawBuilder extends YeepayBuilder{

    protected List<Part> parts = new ArrayList<Part>();
    protected String url= Conts.baseRequestUrl + "/withDrawApi.action";

    private ArrayList<String> needHmac=new ArrayList<>(Arrays.asList(
            "amount",
            "customerNumber",
            "externalNo",
            "mainCustomerNumber",
            "transferWay",
            "callBackUrl"
    ));

    public WithdrawBuilder setMainCustomerNumber(String mainCustomerNumber) {
        this.parts
                .add(new StringPart("mainCustomerNumber",
                        mainCustomerNumber == null ? "" : mainCustomerNumber,
                        "UTF-8"));
        return this;
    }

    public WithdrawBuilder setCustomerNumber(String customerNumber) {
        this.parts
                .add(new StringPart("customerNumber",
                        customerNumber == null ? "" : customerNumber,
                        "UTF-8"));
        return this;
    }

    public WithdrawBuilder setExternalNo(String externalNo) {
        this.parts
                .add(new StringPart("externalNo",
                        externalNo == null ? "" : externalNo,
                        "UTF-8"));
        return this;
    }

    public WithdrawBuilder setTransferWay(String transferWay) {
        this.parts
                .add(new StringPart("transferWay",
                        transferWay == null ? "" : transferWay,
                        "UTF-8"));
        return this;
    }

    public WithdrawBuilder setAmount(String amount) {
        this.parts
                .add(new StringPart("amount",
                        amount == null ? "" : amount,
                        "UTF-8"));
        return this;
    }

    public WithdrawBuilder setCallBackUrl(String callBackUrl) {
        this.parts
                .add(new StringPart("callBackUrl",
                        callBackUrl == null ? "" : callBackUrl,
                        "UTF-8"));
        return this;
    }

    @Override
    public Part[] generateParams() {
        return parts.toArray(new Part[parts.size()]);
    }

    @Override
    public void setHmac(String hmac) {
        this.parts
                .add(new StringPart("hmac",
                        hmac == null ? "" : hmac,
                        "UTF-8"));
    }

    @Override
    public List<String> needHmacArr() {
        return needHmac;
    }

    @Override
    public String getUrl() {
        return this.url;
    }
}
